package com.mode5.m1_simple;

import com.mode5.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/** RabbitMQ系列之三 RabbitMQ 5种典型模式 https://blog.csdn.net/caiqing116/article/details/84032099
 * 简单模式Simple、工作模式Work、发布订阅模式Publish/Subscribe、路由模式Routing、通配符模式Topics、远程调用模式RPC(暂不对该队列模式进行详解)
 */
public class Producter {
    private final static String QUEUE_NAME = "hello";
    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接
        Connection connection = ConnectionUtil.getConnection();
        //从连接中声明通道
        Channel channel = connection.createChannel();
        //队列申明
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //消息内容
        String message = "simple queue hello world !";
        //推送发布消息
        //basicPublish(String exchange, String routingKey, BasicProperties props, byte[] body)
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
        //信道关闭
        channel.close();
        //连接关闭
        connection.close();
    }
}
